﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using ADShop.Models;
namespace ADShop.Controllers
{
    public class ProductManagerController : Controller
    {
        //
        // GET: /ProductManager/
        #region "Variable"
        EShopEntities1 adshop = new EShopEntities1();  //ADShopEntities adshop = new ADShopEntities();
        #endregion
        public ActionResult Index()
        {
            return View();
        }
        public String GetImage(int id)
        {
            return string.Format("<img src='{0}' alt='{1}' class='imgzoomproducts' width='152' height='152'/>", adshop.Product.Where(p => p.IDProduct == id).FirstOrDefault().ProductImage, adshop.Product.Where(p => p.IDProduct == id).FirstOrDefault().NameProduct);
            
        }
        public string GetRating(int id)
        {
            int Num = 0;
            int View = Convert.ToInt32(adshop.Product.Where(d => d.IDProduct == id).SingleOrDefault().View);
            if (View >= 10)
            {
                Num = 1;
            }
            if(View >= 10 && View <= 20)
            {
                Num = 2;
            }
            if (View >= 20 && View <= 30)
            {
                Num = 3;
            }
            if(View >= 40 && View <= 50)
            {
                Num = 4;
            }
            if(View >= 50 )
            {
                Num = 5;
            }
            return string.Format("<img src='/image/stars-{0}.png' alt='Based on {1} reviews.'>", Num, Num);
        }

    }
}
